import 'dart:async';

import 'package:core_package/core_package.dart';
import 'package:core_package/ui/widget/my_asset_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_unionad/model/share_pic_model.dart';
import 'package:flutter_app_unionad/request/facility_request.dart';
import 'package:flutter_app_unionad/ui/my_facility/widget/share_botton_widget.dart';
import 'package:flutter_unionad/flutter_unionad.dart' as FlutterUnionad;
import 'package:flutter_unionad/flutter_unionad_code.dart';

class RechargeFinishAdWidget extends StatefulWidget {
  final String orderID;
  SharePicModel? item;

  RechargeFinishAdWidget({Key? key, required this.orderID, this.item}) : super(key: key);

  static Future show(
    BuildContext context, {
    required String orderID,
    SharePicModel? item,
  }) {
    return ShowCenterAlertDialog.showAlert(
      context,
      builder: (context) {
        return RechargeFinishAdWidget(
          orderID: orderID,
          item: item,
        );
      },
      width: 310.px,
      height: 420.px,
      bgColor: Colors.transparent,
      radius: 0,
    );
  }

  @override
  State<RechargeFinishAdWidget> createState() => _RechargeFinishAdWidgetState();
}

class _RechargeFinishAdWidgetState extends State<RechargeFinishAdWidget> {
  bool isEnd = true;

  late Timer _timer;
  int count = 0;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // _timer = Timer.periodic(Duration(seconds: 1), (timer) {
    //   if (count == 5) {
    //     isEnd = true;
    //     setState(() {});
    //     _timer.cancel();
    //   }
    //   count++;
    // });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    // _timer.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Stack(
          children: [
            Container(
              width: 310.px,
              height: 282.px,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(8.px),
              ),
              child: Column(
                children: [
                  SizedBox(height: 46.px),
                  Text(
                    isEnd ? '订单已完成' : '订单处理中请稍后...',
                    style: TextStyle(
                      color: MyColors.color_27_27_27,
                      fontSize: 16.px,
                    ),
                  ),
                  SizedBox(height: 35.px),
                  // Container(
                  //   color: Colors.red,
                  //   child: FlutterUnionad.FlutterUnionad.nativeAdView(
                  //     androidCodeId: '948640638',
                  //     iosCodeId: '948640637',
                  //     expressViewWidth: 260.px,
                  //     expressViewHeight: 360.px,
                  //     expressNum: 1,
                  //     downloadType: FlutterUnionadDownLoadType.DOWNLOAD_TYPE_POPUP,
                  //   ),
                  // ),
                  FlutterUnionad.FlutterUnionad.bannerAdView(
                    androidCodeId: "948640670",
                    //andrrid banner广告id 必填
                    iosCodeId: "948640674",
                    //ios banner广告id 必填
                    supportDeepLink: true,
                    //是否支持 DeepLink 选填
                    expressAdNum: 1,
                    //一次请求广告数量 大于1小于3 必填
                    expressTime: 5,
                    //轮播间隔事件 30-120秒  选填
                    expressViewWidth: 300.px,
                    expressViewHeight: 150.px,
                    //期望view高度 dp 必填
                    downloadType: FlutterUnionad.FlutterUnionadDownLoadType.DOWNLOAD_TYPE_POPUP,

                    callBack: FlutterUnionad.FlutterUnionadBannerCallBack(onClick: () {
                      print('onClick');
                    }, onShow: () {
                      print('onShow');
                    }, onFail: (msg) {
                      print('onFail');
                    }, onDislike: (msg) {
                      print('onDislike');
                    }),
                  ),
                  // Container(
                  //   width: 260.px,
                  //   height: 160.px,
                  //   color: Colors.green,
                  // )
                ],
              ),
            ),
            Positioned(
              right: 10,
              top: 20,
              child: GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {
                  Navigator.pop(context);
                },
                child: MyAssetImage(
                  "icon_close",
                  width: 20.px,
                  height: 20.px,
                ),
              ),
            ),
          ],
        ),
        SizedBox(height: 26.px),
        if(widget.item!=null)
        ShareBottomWidget(
          item: widget.item,
          shareFinish: () {
            FacilityRequest.rechargeSaveAd(record: widget.orderID,);
          },
        ),
      ],
    );
  }
}
